package com.whjz.dcfs.jzxx.struts.action;

import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.whjz.dcfs.jzxx.dao.IDcfsHjjcdJbxxDAO;
import com.whjz.dcfs.jzxx.model.DcfsHjjcdJbxx;
import com.whjz.dcfs.util.BaseAction;

public class JZSBHJJCDAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	@Autowired
	public IDcfsHjjcdJbxxDAO dcfsHjjcdJbxxDAO;
	private DcfsHjjcdJbxx dcfsHjjcdJbxx;

	public void insertDcfsHjjcdJbxx() throws Exception{
		try{
			getHttpServletResponse().setCharacterEncoding("utf-8");
			dcfsHjjcdJbxxDAO.insertDcfsHjjcdJbxx(dcfsHjjcdJbxx);
			getHttpServletResponse().getWriter().println("{success:'true',msg:'添加成功'}");
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public void updateDcfsHjjcdJbxx() throws Exception{
		try{
			getHttpServletResponse().setCharacterEncoding("utf-8");
			dcfsHjjcdJbxxDAO.updateDcfsHjjcdJbxx(dcfsHjjcdJbxx);
//			System.out.println(dcfsHjjcdJbxx.getJcdbm());
			getHttpServletResponse().getWriter().println("{success:'true',msg:'修改成功'}");
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public void getDcfsHjjcdJbxxByCond_sb() throws Exception{
		try{
			getHttpServletRequest().setCharacterEncoding("utf-8");
			getHttpServletResponse().setCharacterEncoding("utf-8");
//			System.out.println("jcdmc---------------"+URLDecoder.decode(getHttpServletRequest().getParameter("jcdmc"),"utf-8"));
			dcfsHjjcdJbxx.setJcdmc(URLDecoder.decode(getHttpServletRequest().getParameter("jcdmc"),"utf-8"));
			dcfsHjjcdJbxx.setHjzljkdz(URLDecoder.decode(getHttpServletRequest().getParameter("hjzljkdz"), "utf-8"));
//			dcfsHjjcdJbxx.set
			List<DcfsHjjcdJbxx> list=dcfsHjjcdJbxxDAO.getDcfsHjjcdJbxxByCond_sb(dcfsHjjcdJbxx);
			String fsybh="";
			if(list!=null&&list.size()>0){
				for(int i=0;i<list.size();i++){
					fsybh+=list.get(i).getJzsbbh();
					if(i<list.size()-1){
						fsybh+=",";
					}
				}
			}
			getHttpServletResponse().getWriter().println(fsybh);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public void deleteDcfsHjjcdJbxx() throws Exception{
		try{
			String[] bms=dcfsHjjcdJbxx.getJcdbm().split(",");
			List<DcfsHjjcdJbxx> list =new ArrayList<DcfsHjjcdJbxx>();
			DcfsHjjcdJbxx object;
			for (String string : bms) {
				object=new DcfsHjjcdJbxx();
				object.setJcdbm(string);
				list.add(object);
			}
//			dcfsHjjcdJbxxDAO.deleteDcfsHjjcdJbxxByCond(dcfsHjjcdJbxx);
			dcfsHjjcdJbxxDAO.deleteDcfsHjjcdJbxxListByCond(list);
			getHttpServletResponse().getWriter().println("{success:'true',msg:'删除成功'}");
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public void getDcfsHjjcdJbxxListByCond() throws Exception{
		try{
			getHttpServletResponse().setCharacterEncoding("utf-8");
			List<DcfsHjjcdJbxx> listall=dcfsHjjcdJbxxDAO.getDcfsHjjcdJbxxListByCond(dcfsHjjcdJbxx);
			StringBuffer sb=new StringBuffer();
			sb.append("{root:[");
			if(listall!=null&&listall.size()>0){
				for(int i=0;i<listall.size();i++){
					
					sb.append("{");
					sb.append("JCD_BM:'"+(listall.get(i).getJcdbm()==null?"":listall.get(i).getJcdbm())+"',");
					sb.append("JZ_SB_BH2:'"+(listall.get(i).getJzsbbh()==null?"":listall.get(i).getJzsbbh())+"',");
					sb.append("JCD_MC:'"+(listall.get(i).getJcdmc()==null?"":listall.get(i).getJcdmc())+"',");
					sb.append("HJZL_JK_DZ:'"+(listall.get(i).getHjzljkdz()==null?"":listall.get(i).getHjzljkdz())+"',");
					sb.append("HJZL_JK_XZQH:'"+(listall.get(i).getHjzljkxzqh()==null?"":listall.get(i).getHjzljkxzqh())+"',");
					sb.append("JCD_DCQD:'"+(listall.get(i).getJcddcqd()==null?"":listall.get(i).getJcddcqd())+"',");
					sb.append("JCD_GLMD:'"+(listall.get(i).getJcdglmd()==null?"":listall.get(i).getJcdglmd())+"',");
					sb.append("HJZL_JK_LXR:'"+(listall.get(i).getHjzljklxr()==null?"":listall.get(i).getHjzljklxr())+"',");
					sb.append("HJZL_JK_LXDH:'"+(listall.get(i).getHjzljklxdh()==null?"":listall.get(i).getHjzljklxdh())+"',");
					sb.append("JKXT_MN:'"+(listall.get(i).getJkxtmn()==null?"":listall.get(i).getJkxtmn())+"',");
					sb.append("JCLB_MC:'"+(listall.get(i).getJclbmc()==null?"":listall.get(i).getJclbmc())+"',");
					sb.append("JCD_XDJL_CZ:'"+(listall.get(i).getJcdxdjlcz()==null?"":listall.get(i).getJcdxdjlcz())+"',");
					sb.append("JCD_XDJL_SP:'"+(listall.get(i).getJcdxdjlsp()==null?"":listall.get(i).getJcdxdjlsp())+"',");
					sb.append("JCD_XDFW:'"+(listall.get(i).getJcdxdfw()==null?"":listall.get(i).getJcdxdfw())+"',");
					sb.append("JKXT_ZB_JD:'"+(listall.get(i).getJkxtzbjd()==null?"":listall.get(i).getJkxtzbjd())+"',");
					sb.append("JKXT_ZB_WD:'"+(listall.get(i).getJkxtzbwd()==null?"":listall.get(i).getJkxtzbwd())+"',");
					sb.append("HJZL_BZ:'"+(listall.get(i).getHjzlbz()==null?"":listall.get(i).getHjzlbz())+"'");
					
					sb.append("}");
					
					if(i < listall.size()-1){
						sb.append(",");
					}
					
				}
			}
			sb.append("]}");
			getHttpServletResponse().getWriter().println(sb);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public DcfsHjjcdJbxx getDcfsHjjcdJbxx() {
		return dcfsHjjcdJbxx;
	}

	public void setDcfsHjjcdJbxx(DcfsHjjcdJbxx dcfsHjjcdJbxx) {
		this.dcfsHjjcdJbxx = dcfsHjjcdJbxx;
	}
	
	
}
